package com.kingschan.jeasytag.tag.power;

import java.io.Serializable;
import javax.servlet.jsp.JspException;
import com.kingschan.jeasytag.core.annotations.tag.*;
import com.kingschan.jeasytag.tag.RootTag;
import com.kingschan.jeasytag.tag.form.ComboBoxTag;
import com.kingschan.jeasytag.tag.grid.GridTag;
import com.kingschan.jeasytag.tag.grid.TreeGrid;

/**
 * sql语句标签
 * @author kingschan 2013-4-7
 */

@TagMetaData(CssClass = "", tag = "input",initalAttr=" type=\"hidden\""	
)
public class SQLTag extends RootTag implements	 Cloneable,Serializable {

	private static final long serialVersionUID = 1L;
	@PropertyField
	@StringField(description="数据库类型",Regex="[MYSQL]{5}|[SQLSERVER]{9}|[ORACLE]{6}")
	private String DBtype;
	@PropertyField
	@StringField(description="数据库连接")
	private String jdbcConnection;
	@PropertyField
	@JsonArrayField(description="初始化查询条件为josn格式 #{变量名字} 这样访问变量值系统变量有#{rows},#{page},#{filter}#{sort}  #{查询框字段变量}")
	private String initalData;
	@PropertyField
	@StringField(description="sql语句")
	private String sql;

	
	
	@Override
	protected Object clone() throws CloneNotSupportedException {
		return super.clone();
	}

	@Override
	public int doEndTag() throws JspException {
		this.sql=this.getBodyContent().getString();		
		try {
			if (this.getParent() instanceof GridTag) {
				GridTag grid = (GridTag) this.getParent();
				SQLTag gs = (SQLTag) this.clone();
				grid.setSqltag(gs);
			}else if (this.getParent() instanceof TreeGrid) {
				TreeGrid tree = (TreeGrid) this.getParent();
				SQLTag gs = (SQLTag) this.clone();
				tree.setSqltag(gs);
			}else if (this.getParent() instanceof ComboBoxTag) {
				ComboBoxTag com = (ComboBoxTag) this.getParent();
				SQLTag gs = (SQLTag) this.clone();
				com.setSqltag(gs);
			}
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return super.doEndTag();
	}

	



	public String getDBtype() {
		return DBtype;
	}

	public void setDBtype(String dBtype) {
		DBtype = dBtype;
	}

	public String getJdbcConnection() {
		return jdbcConnection;
	}

	public void setJdbcConnection(String jdbcConnection) {
		this.jdbcConnection = jdbcConnection;
	}

	public String getInitalData() {
		return initalData;
	}

	public void setInitalData(String initalData) {
		this.initalData = initalData;
	}

	public String getSql() {
		return sql;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}

	
	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	

	

}